<?php
/**
 *  盲盒用户表
 * ds
 * 2020.08.13
 */

namespace App\Models\MainDB;

use Illuminate\Database\Eloquent\Model;

class GiftBoxUserPond extends Model
{

    protected $table = 'ln_gift_box_user_pond';     //数据库内完整表名

    protected $primaryKey = 'id';    //主键名

    protected $fillable = [
        'id',      //主键id
        'user_id',    //用户id
        'type',       //盲盒类型；7：铜，8：银，9：金
        'gift_id',   //礼物id
        'number',      //数量
    ];

    public $timestamps = false;

    public function getList($userId, $type)
    {
        $where['t1.user_id'] = $userId;
        $where['t1.type'] = $type;

        $data = $this->from('ln_gift_box_user_pond as t1')
            ->leftJoin('ln_gift as t3', 't1.gift_id', '=', 't3.id')
            ->select('t1.id', 't3.name as gift_name', 't3.price', 't3.picture', 't1.number', 't1.gift_id')
            ->where($where)
            ->orderBy('t1.id', 'desc')
            ->get()
            ->toArray();
        return $data;
    }
}
